<template>
    <div class="bg-white grid-content">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">

        <el-form-item label="">
          <el-select v-model="formInline.label" placeholder="请选择字段名称" @change="getBmc">
            <el-option
            v-for="item in options"
            :key="item.id"
            :label="item.lmc"
            :value="item.zdmc">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <el-select v-model="formInline.condition" placeholder="请选择查询条件">
            <el-option label="=" value="="></el-option>
            <el-option label="!=" value="<>"></el-option>
            <el-option label=">" value=">"></el-option>
            <el-option label="<" value="<"></el-option>
            <el-option label=">=" value=">="></el-option>
            <el-option label="<=" value="<="></el-option>
            <el-option label="前模糊" value="1"></el-option>
            <el-option label="后模糊" value="2"></el-option>
            <el-option label="全模糊" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <el-input v-model="formInline.value" placeholder="请输入字段值"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary"  @click="emitSubmit">查询</el-button>
          <el-button type="primary"  @click="emitdownload">下载</el-button>
          <el-button type="success"  @click="emitsave">上报</el-button>
        </el-form-item>

      </el-form>
    </div>
</template>
<script>
import sjzdApi from '@/api/sjtb/generalquery';
import infoApi from "@/api/dtbb/info";

export default {
   props: ["bbid"],
   data() {
      return {
        formInline:{
            label:'',
            condition:'',
            value:'',
        },
        options:[],
        bmc:'',
      }
   },
   created(){
   },
   mounted(){
    this.search();
   },
   computed:{
   },
   methods:{
    async search() {
      //发送查询请求
      let res = await infoApi.getList({bbid:this.bbid});
      //判断是否成功
      if(res.success){
        console.log(res.data);
        console.log(this.bbid);
        this.options = res.data;
      }
    },
    //触发父组件的方法
    emitSubmit(){
        this.$emit('onEmitSearch', this.formInline,this.bmc)
    },
    emitdownload(){
        this.$emit('download')
    },
    emitsave(){
        this.$emit('saveSQL',this.formInline)
    },
    getBmc(val){
      console.log(val);
      var bmcObj = this.options.filter(item => item.zdmc == val);
      console.log(bmcObj);
      this.bmc = bmcObj[0].bmc;
    }
   },
}
</script>
<style lang="scss" scoped>
.bg-white {
  background: #ffffff;
}

.grid-content {
  padding: 0px 10px 0px 10px;
  margin-bottom: 10px;
  border-radius: 4px;
}

.el-form-item {
  margin: 15px 10px 15px 10px;
}

</style>
